package com.hackerrank.challenges.botcleanv2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {
	private static char[][] mem = {{'o', 'o', 'o', 'o', 'o'}, {'o', 'o', 'o', 'o', 'o'}, {'o', 'o', 'o', 'o', 'o'}, {'o', 'o', 'o', 'o', 'o'}, {'o', 'o', 'o', 'o', 'o'}};
	/* Head ends here */
	private static void next_move(int posx, int posy, String[] board) {
		// copy the visible area to memory
		int minrow = Math.max(posx - 1, 0), maxrow = Math.min(posx + 1, board.length - 1);
		int mincol = Math.max(posy - 1, 0), maxcol = Math.min(posy + 1, board.length - 1);
		for(int i = minrow; i <= maxrow; i++) {
			char[] c = board[i].toCharArray();
			for(int j = mincol; j <= maxcol; j++)
				mem[i][j] = c[j];
		}
		// find the closest d
		int md = Integer.MAX_VALUE, mx = posx, my = posy;
		for(int i = 0; i < mem.length; i++) {
			for(int j = 0; j < mem[i].length; j++) {
				if(mem[i][j] == 'd') {
					int d = Math.abs(posx - i) + Math.abs(posy - j);
					if(d < md) {
						md = d;
						mx = i;
						my = j;
					}
				}
			}
		}
		if(mx < posx)
			System.out.println("UP");
		else if(mx > posx)
			System.out.println("DOWN");
		else if(my < posy)
			System.out.println("LEFT");
		else if(my > posy)
			System.out.println("RIGHT");
		else if(board[posx].charAt(posy) == 'd')
			System.out.println("CLEAN");
		else {
			// find the closest o
			md = Integer.MAX_VALUE;
			List<Integer> m2x = new ArrayList<Integer>();
			List<Integer> m2y = new ArrayList<Integer>();
			for(int i = 0; i < mem.length; i++) {
				for(int j = 0; j < mem[i].length; j++) {
					if(mem[i][j] == 'o') {
						int d = Math.abs(posx - i) + Math.abs(posy - j);
						if(d < md) {
							md = d;
							m2x.clear();
							m2x.add(i);
							m2y.clear();
							m2y.add(j);
						} else if(d == md) {
							m2x.add(i);
							m2y.add(j);
						}
					}
				}
			}
			int r = (int)(Math.random() * m2x.size());
			mx = m2x.get(r);
			my = m2y.get(r);
			if(mx < posx)
				System.out.println("UP");
			else if(mx > posx)
				System.out.println("DOWN");
			else if(my < posy)
				System.out.println("LEFT");
			else if(my > posy)
				System.out.println("RIGHT");
		}
	}

	/* Tail starts here */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int [] pos = new int[2];
		String board[] = new String[5];
		for(int i=0;i<2;i++) pos[i] = in.nextInt();
		for(int i=0;i<5;i++) board[i] = in.next();
		in.close();
		next_move(pos[0], pos[1], board);
	}
}
